<link rel="stylesheet" href="/assets/home/css/poster.css" />

<header class="mui-bar mui-bar-nav mui-bar-nav-bg">
    <a id="icon-menu" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title">推广海报</h1>
</header>


<div class="content">
    <div class="poster">
        <img id="poster" src="{$auth.poster ? $auth.poster : ''}" alt="点击按钮重新生成海报" />
    </div>


    <div class="link">
        <input type="text" placeholder="普通输入框" id="url" value="{$url}" />
        <button class="mui-btn mui-btn-primary" type="button" id="btn">点击复制</button>
    </div>

    <div class="update">
        <button class="mui-btn mui-btn-success" type="button" id="update">重新生成海报</button>
    </div>
</div>

<script>
    let poster = $('#poster').attr('src');

    // 更新海报点击事件
    $('#update').click(function () {
        $.ajax({
            type: 'post',
            dataType: 'json',
            success: function (res) {
                // console.log(res);
                if (res.code === 1) {
                    $('#poster').attr('src',res.data.poster);
                }
            }
        })
    });

    // 复制推广地址
    $('#btn').click(function () {
        let url = $('#url');

        // 选中地址
        url.select();

        // 执行复制指令
        document.execCommand('copy',false);

        mui.toast('复制成功');
    });

    // 如果海报为空
    if (!poster) {
        // 模拟事件
        $('#update').click();
    }
</script>